
//
//  HDOneToManyHandler.swift
//  Wmsmobile
//
//  Created by xuNick on 16/9/8.
//  Copyright © 2016年 www.hd123.com. All rights reserved.
//

import UIKit

class HDOneToManyHandler: NSObject {
    class func GetArticleByOwner(_ piArticleCode: String ,piOwner : String , success: @escaping (_ dict: [String : String]) -> () , failed: @escaping (_ dict: [String : String]) -> () , netError: () -> ()){
        NetworkTool.sharedTools.postSoap(["piArticleCode" : piArticleCode , "piOwner" : piOwner], bodyMethod: "GetArticleByOwner",suffix: nil, success: { (data) in
            let result = analysisManager.shareManager.XmlParserAnalysis(XMLParser(data: data), elementName: "collect")
            let resultMsgs = analysisManager.shareManager2.XmlParserAnalysis(XMLParser(data: data), elementName: "GetArticleByOwnerResponse").first!
//            self!.allInfo += resultMsgs
            guard resultMsgs["GetArticleByOwnerResult"] == "0" else {
                failed(resultMsgs)
                return
            }
            if result.count > 1 {
                let selectorView = SelectTableView(dataArray: result)
                selectorView.showSelector(UIApplication.shared.keyWindow!, success: { (dict) in
                    success(dict)
                    })
            }else{ //只有一个货物就直接赋值走人
                success(result.first!)
            }
            }, failed: {
             //TODO: 网络请求失败 一码多品
        })

    }
    class func GetArticleByBin(_ piArticleCode: String ,piBin : String , success: @escaping (_ dict: [String : String]) -> () , failed: @escaping (_ dict: [String : String]) -> (), netError: () -> ()){
        NetworkTool.sharedTools.postSoap(["piArticleCode" : piArticleCode , "piBin" : piBin], bodyMethod: "GetArticleByBin",suffix: nil, success: { (data) in
            let result = analysisManager.shareManager.XmlParserAnalysis(XMLParser(data: data), elementName: "collect")
            let resultMsgs = analysisManager.shareManager2.XmlParserAnalysis(XMLParser(data: data), elementName: "GetArticleByBinResponse").first!
            //            self!.allInfo += resultMsgs
            guard resultMsgs["GetArticleByBinResult"] == "0" else {
                failed(resultMsgs)
                return
            }
            if result.count > 1 {
                let selectorView = SelectTableView(dataArray: result)
                selectorView.showSelector(UIApplication.shared.keyWindow!, success:
                    { (dict) in
                    success(dict)
                })
            }else{ //只有一个货物就直接赋值走人
                success(result.first!)
            }
            }, failed: {
                //TODO: 网络请求失败 一码多品
        })

    }
}
